<?php

class MatchController extends Controller
{
	
	protected $matches;
	
	public function accessRules() {
		return array(
				array('deny',
						'actions' => array('index'),
						'users' => array('?'),
				)
		);
	}
	
	public function filters() {
		return [ 'accessControl'];
	}	
	
	public function actionIndex()
	{
		$this->matches = Matches::model()->findAllByAttributes( [ 'idJourney' => Yii::app()->user->currentJourney,
			'idSeason' => Yii::app()->user->currentSeason, 'idLeague' => Yii::app()->user->currentLeague ] );
		
		foreach( $this->matches as $match ){
			$matchesOdds = Odds::model()->findAllByAttributes( [ 'idMatch'  => $match->idMatch ] );
			var_dump( $matchesOdds ); exit;
			$match->setAttribute( 'matchesOdds', $matchesOdds );
			var_dump( $match->getAttribute( 'matchesOdds' ) ); exit;
			$userOdds = UsersOdds::model()->findByAttributes(
					[ 'idUser' => Yii::app()->user->id, 'idTournament' => Yii::app()->user->currentTournament,
					 'idMatch' => $match->idMatch ] );
			$match->setAttribute( 'userOdds', $userOdds );
		}
		
		echo "Hola"; exit;
		
		$this->render('index');
	}
}